﻿using System.Drawing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using Jacobi.Vst.Interop.Host;

namespace Play.TrackManagement
{
	public class Track
	{
		public Track(VstPluginContext pluginContext)
		{
			PluginContext = pluginContext;
		}

		public VstPluginContext PluginContext { get; private set; }

		public void ShowEditor()
		{
			Rectangle rect;
			if (!PluginContext.PluginCommandStub.EditorGetRect(out rect))
				return;

			// ContentHolder ist nur ein Dummy, damit die 
			// _innere_ Fenstergröße dem des Plugin-Editors entspricht.
			var contentHolder = new ContentControl { Width = rect.Width, Height = rect.Height };
			var window = new Window
			{
				Content = contentHolder,
				SizeToContent = SizeToContent.WidthAndHeight,
				ResizeMode = ResizeMode.NoResize
			};
			window.Loaded += (s, e) =>
				PluginContext.PluginCommandStub.EditorOpen(
					new WindowInteropHelper(window).Handle);
			window.Show();
		}
	}
}